# XOR encryption requires GNU gawk - Michael S. Sanders
# license: GPL3

BEGIN {

tmp1 = xorEncode("Nifty", "My Password")
tmp2 = xorEncode(tmp1, "My Password")

print tmp1
print tmp2

}

# ---------------------------------------------------------------------------

function xorEncode(str, pass,    x, y, z, j, ord_a, str_a, pass_a, buf) {

# more info about xor at:
# http://en.wikipedia.org/wiki/XOR_cipher
# note: xor is specific to GNU gawk

    x = split(str,  str_a,  "")
    y = split(pass, pass_a, "")

    for (z = 1; z <= 255; z++) {ord_a[sprintf("%c", z)] = z}

    for (j = z = 1; z <= x; z++) {
        buf = buf sprintf("%c", xor(ord_a[str_a[z]], ord_a[pass_a[j]]))
        j = (j < y) ? j++ : 1
    }

    return buf

}
